﻿<?php require_once(dirname(__FILE__)."/../config/config.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理员管理页面</title>
</head>
<body>
<?php  
if($_SESSION['admin_name']=="")
{

	echo "<script>location.href='admin_login.php';</script>";
}
?>
 <?php 
 // 1 定义分页变量
 	$page = isset($_GET["page"])?$_GET["page"]:1;					//当前页号
	$pageSize = 20;				//页面大小	
	$maxRows;					// 最大数据条
	$maxPages;					// 最大页数
 // 2获取最大数据条数
 	$sql = "select count(*) from zy_admin";
	$res = mysql_query($sql);
	$maxRows = mysql_result($res,0,0);//定位获取总条数
 // 3计算出共计最大页数
 	$maxPages=ceil($maxRows/$pageSize);
	$init = 1;
	$max = $maxPages;
	$pagelen = 10;
	// $pagelen = ($pagelen%2)?$pagelen:$pagelen+1;
	$pageoffset = 4;
	if($maxPages>$pagelen){
		if($page<=$pageoffset)
		{
			$init=1;
			$max = $pagelen;
		}else{
			if($page+$pageoffset>=$maxPages+1){
				$init = $maxPages-$pagelen+1;
			}else{
				$init = $page-$pageoffset;
				$max=$page+$pageoffset+1;
			}	
		}
	}
 // 4 效验当前页数
 	if($page>$maxPages){
		$page=$maxPages;
	}
	if($page<1){
		$page=1;
	}
 //5 拼装分页sql语句片段
	$limit = " limit ".(($page-1)*$pageSize).",{$pageSize}"; ?>
<center>
<h2>管理员管理系统</h2>
	<a href="admin_list.php">管理员账号列表</a> |
	<a href="admin_registration.php?page=<?php echo $page ?>">注册管理账号息</a>  |
	<hr width="90%" />
 <h3>分页浏览管理员信息</h3>
<table width="800" border="1" align="center">
 <tr>
    <th>管理员账号</th>
    <th>管理员密码</th>
    <th>备注</th>
	<th>操作</th>
</tr>

<?php
 $sql = "SELECT * FROM zy_admin {$limit}";
 $result = mysql_query($sql);
 while($zy_admin = mysql_fetch_array($result)){
 ?>
  <tr>
   <td><?php echo $zy_admin['admin_name'];?></td>
    <td><?php echo $zy_admin['admin_password'];?></td>
    <td><?php echo $zy_admin['remark'];?></td>
	<td align="center">
	<a href="admin_action.php?action=del&admin_id=<?php echo $zy_admin['admin_id'];?>&page=<?php echo $page ?> ">删除</a>&nbsp;&nbsp;	    
	<a href="admin_edit.php?admin_id=<?php echo $zy_admin['admin_id'];?>&page=<?php echo $page;?>">修改</a></td>
  </tr>
  <?php }?>
</table>
<?php
	//输出分页信息显示上一页和下一页
	echo "<br/><br/>";
	echo "当前{$page}/{$maxPages}页 共计{$maxRows}条 ";
	echo "<a href='admin_list.php?page=1'>首页</a> ";
	echo "<a href='admin_list.php?page=".($page-1)."'>上一页</a> ";
		for($i=$init;$i<=$max;$i++)
	{
		echo"<a href='admin_list.php?page=".($page=$i)."'> $i</a> ";
	}
	echo "<a href='admin_list.php?page=".($page+1)."'>下一页</a> ";
	echo "<a href='admin_list.php?page={$maxPages}'>末页</a> ";
?>
当前第<?php echo $page ;?>页
</center>
<h3 align="center"><a href="admin_management.php">返回</a></h3>
</body>
</html>